<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html>
<html>
<head>

<link rel='SHORTCUT ICON' href='<s:url value="/theme/img/carepad.png" />' />

<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="description" content="Axiohelix CarePAD" />
<meta name="keywords" content="Axiohelix, Home Electronics" />
<meta name="author" content="Axiohelix" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />

<link href="<s:url value='/theme/css/jquery-ui.min.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/contextMenu.css'/>" rel="stylesheet">
<link href="<s:url value='/theme/css/jquery.sliderTabs.css' />"	rel="stylesheet" />
<link href="<s:url value='/theme/css/mobiscroll.core-2.6.2.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/mobiscroll.sense-ui-2.6.2.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/jquery.jqplot.min.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/jquery.mobile-1.3.2.min.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/jquery.mobile.structure-1.3.2.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/jquery.mobile.theme-1.3.2.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/style.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/jqm-demos.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/jqm-datebox.min.css' />" rel="stylesheet" />
<link href="<s:url value='/theme/css/table.css'/>" rel="stylesheet">

<script src="<s:url value='/theme/js/index.js'/>"></script>
<script src="<s:url value='/theme/js/jqm-demos.js'/>"></script>
<script src="<s:url value='/theme/js/jquery-1.10.2.min.js'/>"></script>
<script src="<s:url value='/theme/js/jquery-ui.min.js'/>"></script>
<script src="<s:url value='/theme/js/contextMenu.js'/>"></script>
<script src="<s:url value='/theme/js/jquery.storage.js'/>"></script>
<script src="<s:url value='/theme/js/jquery.sliderTabs.js'/>"></script>
<script src="<s:url value='/theme/js/mobiscroll.core-2.6.2.js'/>"></script>
<script src="<s:url value='/theme/js/mobiscroll.datetime-2.6.2.js'/>"></script>
<script src="<s:url value='/theme/js/jquery.jqplot.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqplot.highlighter.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqplot.cursor.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqplot.pointLabels.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqplot.dateAxisRenderer.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqplot.canvasTextRenderer.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqplot.canvasAxisTickRenderer.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jquery.mobile-1.3.2.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqm-datebox.core.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jqm-datebox.mode.datebox.min.js'/>" type="text/javascript" ></script>
<script src="<s:url value='/theme/js/jquery.touchSwipe.min.js'/>" type="text/javascript" ></script>

<script type="text/javascript">
	
	var vital0max = parseInt("<s:text name='input.BPH.Max.Value'/>");
	var vital0min = parseInt("<s:text name='input.BPH.Min.Value'/>");
	var vital0default = parseInt("<s:text name='input.BPH.Default.Value'/>");
	
	var vital1max = parseInt("<s:text name='input.BPL.Max.Value'/>");
	var vital1min = parseInt("<s:text name='input.BPL.Min.Value'/>");
	var vital1default = parseInt("<s:text name='input.BPL.Default.Value'/>");
	
	var vital2max = parseInt("<s:text name='input.PR.Max.Value'/>");
	var vital2min = parseInt("<s:text name='input.PR.Min.Value'/>");
	var vital2default = parseInt("<s:text name='input.PR.Default.Value'/>");
	
	var vital3max = parseInt("<s:text name='input.BT.Max.Value'/>");
	var vital3min = parseInt("<s:text name='input.BT.Min.Value'/>");
	var vital3default = parseInt("<s:text name='input.BT.Default.Value'/>");
	
	var bias = 27;
	var eleheight = 32;
	var save_form = false;
	
	function incrementValue(id){			
		var max = 0;
		var def = 0;
		
		if (id=="#vital0"){
			max = vital0max;
			def = vital0default;
		} else if (id=="#vital1"){
			max = vital1max;
			def = vital1default;
		} else if (id=="#vital2"){
			max = vital2max;
			def = vital2default;
		} else if (id=="#vital3"){
			max = vital3max;
			def = vital3default;
		}
		
		if (id=="#vital3"){
			value = parseFloat($(id).val());
		} else {
			value = parseInt($(id).val());
		}
		
		if(isNaN(value)){
			value = def;			
		} 
		
		if(value < max){
			if(id=="#vital3"){
				$(id).val((value+0.1).toFixed(1));
			}
			else $(id).val(value+1);
		}
	}
	
	function decrementValue(id){
		var min = 0;
		var def = 0;
		
		if (id=="#vital0"){
			min = vital0min;
			def = vital0default;
		} else if (id=="#vital1"){
			min = vital1min;
			def = vital1default;
		} else if (id=="#vital2"){
			min = vital2min;
			def = vital2default;
		} else if (id=="#vital3"){
			min = vital3min;
			def = vital3default;
		}
		
		if (id=="#vital3"){
			value = parseFloat($(id).val());
		} else {
			value = parseInt($(id).val());
		}
		
		if(isNaN(value)){
			value = def;
		} 
		
		if(value > min){
			if(id=="#vital3"){
				$(id).val((value-0.1).toFixed(1));
			}
			else $(id).val(value-1);
		}
	}
	
	function getmoveindex(vitalstart, vitalend, currntvital, direction, distance){
	
		var startval = bias;
		var endval = startval-((vitalend-vitalstart)*(eleheight));
		var currntval = startval-((currntvital-vitalstart)*(eleheight));
		
		if(direction=="down"){
			currntval = currntval + distance;
		} else if (direction=="up"){
			currntval = currntval - distance;
		}
		
		if(currntval < endval){
			return endval;
		} else if(currntval > startval) {
			return startval;
		} else {
			return currntval;
		}
	}
	
	function getroundupindex(disindex){		
	
		currntvalindex = (disindex-bias)/eleheight;
		currntvalindex = Math.round(currntvalindex);
		dis = currntvalindex*eleheight+bias;
		
		return dis;
	}
	
	function getindexpos(roundupindex){
		return ((roundupindex-bias)/eleheight)*(-1);
	}
	
	function getvitalval(vitalstart, roundupdisindex){				
		var currntvital = ((-roundupdisindex+bias)/eleheight) + vitalstart;	
				
		return currntvital;
	}
	
	function setvitalval(id, vital, vitalstart, vitalend, direction, distance){
	
		index = getmoveindex(vitalstart, vitalend, vital, direction, distance);
		roundupdisindex = getroundupindex(index);
		pos = getindexpos(roundupdisindex);

		$(id+"swap").find(".ui-body-a").attr("class","ui-body-d");
		
		$(id+"fcv00").attr("style","margin-top: "+roundupdisindex+"px;");
		$(id+"fcv0"+pos).attr("class","ui-body-a");
	}
	
	
	function createvitaldata(id, start, end){
	
		var str = "<ul>";		
		var j=0;
		
		for(var i=start; i<end; i++){
		
			if(id=="vital3"){	
				str += '<li id="'+id+'fcv0'+j+'" class="ui-body-d"><span>'+i/10+'</span></li>';
			} else {
				str += '<li id="'+id+'fcv0'+j+'" class="ui-body-d"><span>'+i+'</span></li>';
			}
			j++;
		}
		str += "</ul>";
		
		$("#"+id+"swap").append(str);
	}
	
	function swipevital(id,min,max){
		
		if(id=="vital3"){
			vitalval = $("#"+id).val()*10;
		} else {
			vitalval = $("#"+id).val();
		}
		createvitaldata(id,min,max);
		setvitalval("#"+id, vitalval, min, max, "up", 0);
	
		$("#"+id+"swap").swipe({			
			swipeStatus:function(event, phase, direction, distance, duration, fingers) {
				
				if(id=="vital3"){
					curntval = ($("#"+id).val())*10;
				} else {
					curntval = $("#"+id).val();
				}
				
				dis = getmoveindex(min, max, curntval, direction, distance);
				
				if(phase=="start"){
					save_form = true;
					
					dis = getroundupindex(dis);
					pos = getindexpos(dis);
					$("#"+id+"fcv0"+pos).attr("class","ui-body-d");
				
				}else if(phase=="end"){
					dis = getroundupindex(dis);
					pos = getindexpos(dis);
					
					if(id=="vital3"){
						$("#"+id).val(getvitalval(min,getroundupindex(dis))/10);
					} else {
						$("#"+id).val(getvitalval(min,getroundupindex(dis)));
					}
					$("#"+id+"fcv0"+pos).attr("class","ui-body-a");
				}
				
				$("#"+id+"fcv00").attr("style","margin-top: "+dis+"px;");
			},
			threshold:200,
			maxTimeThreshold:5000,
			fingers:'all'
		});
	}
	
	function getDefaultValue(id){
		var defaultValue = 0;
		var min=0;
		var max=0;
		
		if(id=="#vital0"){
			defaultValue = vital0default;
			min = vital0min;
			max = vital0max;
		} else if(id=="#vital1"){
			defaultValue = vital1default;
			min = vital1min;
			max = vital1max;
		} else if(id=="#vital2"){
			defaultValue = vital2default;
			min = vital2min;
			max = vital2max;
		} else if(id=="#vital3"){
			defaultValue = vital3default;
			min = vital3min*10;
			max = vital3max*10;
		}
	
		$(id).val(defaultValue);
		
		if(id=="#vital3"){
			defaultValue= defaultValue*10;
		}
		setvitalval(id, defaultValue, min, max, "up", 0);
	}
	
	$(document).ready(function() {

		$("#vital0").val(vital0default);
		$("#vital1").val(vital1default);
		$("#vital2").val(vital2default);
		$("#vital3").val(vital3default);
			
	});
	
</script>